package com.example.commons.core


import java.time.*

inline val Long?.dateTimeValue: LocalDateTime
    get() = if (this == null || this == 0L) LocalDateTime.now() else LocalDateTime.ofInstant(
        Instant.ofEpochMilli(this),
        ZoneId.systemDefault()
    )

inline val LocalDateTime?.longValue: Long
    get() = this?.atZone(ZoneId.systemDefault())?.toInstant()?.toEpochMilli() ?: 0L

inline val Long.dateValue: LocalDate
    get() = if (this == 0L) LocalDate.now() else LocalDateTime.ofInstant(
        Instant.ofEpochMilli(
            this
        ), ZoneId.systemDefault()
    ).toLocalDate()

inline val LocalDate?.longValue: Long
    get() = this?.atStartOfDay(ZoneId.systemDefault())?.toInstant()?.toEpochMilli() ?: 0L


fun revertFloatList(value: String): List<Float> {
    if (value.isBlank()) {
        return ArrayList<Float>()
    }

    return value.split(",")
        .map { it.toFloat() }
        .toMutableList()
}

fun convertFloatList(value: List<Float>): String {
    if (value.isEmpty()) {
        return ""
    }

    return value.joinToString(",")
}

